<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Reg_check extends CI_Controller {

	function __construct()
	{
		parent::__construct();
	}

	public function index()
	{
		$this->load->model('user_m');
		$this->load->helper('url');
		if($_POST['auth']=="管理员"){
			$auth=3;
		}else if($_POST['auth']=="普通会员"){
			$auth=2;
		}else{
			$auth=1;
		}

		if(($this->user_m->user_SelectByUserName($_POST['user']))==null){
			$arr=array(
				'username'=>$_POST['user'],
				'password'=>md5($_POST['pass']),		
				'auth'=>$auth
			);
			$this->user_m->user_insert($arr);
			setcookie('username',$_POST['user'],time()+60*60*12);
			setcookie('auth',$auth,time()+60*60*12);
			echo "<script language='javascript' type='text/javascript'>";
			echo 'alert("注册成功!");';
			echo "</script>";
			redirect('?count=0','refresh');	
		}else{
			echo "<script language='javascript' type='text/javascript'>";
			echo 'alert("已注册的账户名!");';
			echo "</script>";
			redirect('?count=0','refresh');	
		}
	}

}
?>